<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 回文对 -->
    <script>
      var isPalindrome = str => {
        let l = 0
        let r = str.length - 1
        while (l < r) {
          if (str[l] != str[r]) return false
          l++
          r--
        }
        return true
      }
      var palindromePairs = words => {
        let res = []
        for (let i = 0; i < words.length; i++) {
          for (let j = i + 1; j < words.length; j++) {
            if (isPalindrome(words[i] + words[j])) res.push([i, j])
            if (isPalindrome(words[j] + words[i])) res.push([j, i])
          }
        }
        return res
      }
      console.log(palindromePairs(['abcd', 'dcba', 'lls', 's', 'sssll']))
    </script>
  </body>
</html>
